package com.xca.is.repository;

import com.xca.is.entity.Weather;
import com.xca.is.service.WeatherService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class WeatherRepository {
    private static final String URL = "http://apis.juhe.cn/" ;
    private static final String KEY = "251518e073ef6c3c9504dd286c3f6a86" ;
    private WeatherService service ;
    public WeatherRepository(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(URL)
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build() ;
        service = retrofit.create(WeatherService.class) ;
    }

    public Observable<Weather> getData(String city){
        return service.getData(city , KEY)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io());
    }
}
